import copy
import time
from struct import pack

import feapder
from Crypto.Cipher import DES
from Crypto.Util.Padding import pad
from feapder import Request
from feapder.dedup import ExpireFilter, Dedup
from feapder.utils import tools

# from setting import REDIS_FILTER_CONN, REDIS_PROXY_CONN
from datetime import datetime, timedelta, date
from feapder.utils.log import log as logger


# def get_proxy():
#     ip = REDIS_PROXY_CONN.srandmember('proxy').decode()
#     proxy = {
#         'http': f'http://{ip}',
#         'https': f'http://{ip}'
#     }
#     return proxy



def des_encrypt(text):
    key = iv = {"sigBytes": 8, "words": [892613430, 926429497]}
    key = pack('>II', *key['words'])
    iv = pack('>II', *iv['words'])
    cipher = DES.new(key, DES.MODE_CBC, iv)
    padded_text = pad(text.encode('utf-8'), DES.block_size)
    ciphertext = cipher.encrypt(padded_text)
    return ciphertext.hex()
